<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>款包封条管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	业务管理
	<span class="c-gray en">&gt;</span>
	款包封条管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
	<div class="text-c"> 
		分公司:
		<span class="select-box inline">
		<select class="select" id="comId" name="comId">
			<option value="">请选择分公司</option>
		</select>
		</span>
		票务室:
		<span class="select-box inline">
		<select class="select" id="toId" name="toId">
			<option value="">请选择票务室</option>
		</select>
		</span>
		<select class="select" id="AllOffice" name="AllOffice" style="display: none;">
		</select>
		季度:
		<span class="select-box inline">
		<select class="select" id="quarter" name="quarter">
			<option value="0">请选择季度</option>
			<option value="1">第一季度</option>
			<option value="2">第二季度</option>
			<option value="3">第三季度</option>
			<option value="4">第四季度</option>
		</select>
		</span>
		<input type="text" name="pocketTag" id="pocketTag" placeholder="款包封条号码（非必填）" style="width:250px" class="input-text">
		<button name="" id="" onclick="getPocketTag();" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>查询</button>
	</div>
	
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a class="btn btn-primary radius" onclick="system_category_add('封条号码入库','baseinfo-pocket-tag-add.html')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 封条号码入库</a>
		</span>
		<span class="l" style="margin:0 0.625rem;">&nbsp;</span>
		<span class="l">
			<a class="btn btn-primary radius" onclick="system_category_add('整包封条号码分发','baseinfo-pocket-tag-update.html')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 整包封条号码分发</a>
		</span>
		<span class="l" style="margin:0 0.625rem;">&nbsp;</span>
		<span class="l">
			<a class="btn btn-primary radius" onclick="testButton()" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i>零散封条号码分发</a>
		</span>
	</div>
	<div class="mt-20">
		<table id="table" class="table table-border table-bordered table-bg table-hover table-sort" style="width: 99%;">
			<thead>
				<tr class="text-c">
					<th width="3%">
						<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
							<input type="checkbox" name="codeCheckbox"/>
						<span></span>
						</label>
					</th>
					<th width="10%">所属企业</th>
					<th width="10%">所属部门</th>
					<th width="8%">封条号码</th>
					<th width="8%">封条类型</th>
					<th width="13%">入库时间</th>
					<th width="13%">分发时间</th>
					<th width="8%">使用状态</th>
					<th width="13%">使用时间</th>
					<th width="5%">季度</th>
					<th style="display: none;"></th>
				</tr>
			</thead>
			<tbody id="tbody">
			</tbody>
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script>
/*系统-封条-添加*/
function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}

var comId;
var toId;
function testButton(){
	var idAndCode = "";
	var ids = "";
	var codes = "";
	$.each($('.checked:checked'), function() {
		idAndCode += this.value+",";
	});
	var reg=/,$/gi; 
	idAndCode = idAndCode.replace(reg,"");
	console.log(idAndCode);
	if(idAndCode == ""){
		window.alert("未选择任何封条号码，请重新选择！");
		return;
	}
	var idAndCodeArr = idAndCode.split(",");
	for(var i=0;i<idAndCodeArr.length;i+=2){
		codes += idAndCodeArr[i]+",";
		ids += idAndCodeArr[i+1]+",";
	}
	codes = codes.replace(reg,"");
	ids = ids.replace(reg,"");
	console.log(codes+"----"+ids);
	localStorage.setItem("codes",codes);
	localStorage.setItem("ids",ids);
	layer_show("零散封条号码分发","baseinfo-pocket-tag-updateByOne.html");
}
$(function(){
	var userinfo = getUserInfo();
	var username =userinfo.username;
	console.log(username);
	var myArray;

	$.ajax({
		type: 'get',
		url: report_service+'/getAllCompany',
		dataType: 'json',
		async: false,
		success: function(data){
			var list =  eval('(' + data.list + ')');
			for(var i = 0;i<list.length;i++){
				$("#comId").append("<option value='"+list[i].companyid+"'>"+list[i].companyname+"</option>");				
			}
		},
		error: function(data){
			console.log(data.msg);
		}
	});
	
	
	$.ajax({
		type: 'get',
		url: report_service+'/getTicktOfficeByCom',
		data:{
			"comId": comId
		},
		dataType: 'json',
		async: false,
		success: function(data){
			var list =  eval('(' + data.list + ')');
			for(var i=0;i<list.length;i++){
				var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
				$("#AllOffice").append(option);
			}
		},
		error: function(data){
			console.log(data.msg);
		}
	});
	
	$.ajax({
		type: 'get',
		url: report_service+'/getUserByname',
		data:{
			"username": username
		},
		async: false,
		/* beforeSend: function (request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					}, */
		dataType: 'json',
		success: function(data){
			console.log(data.list);
			var list =  eval('(' + data.list + ')');
			console.log(list[0].officeId+"--"+list[0].companyId);
			if(list[0].officeId.indexOf("1")==0){
				console.log("票务室人员登录");
				$("#comId").val(list[0].companyId);
				comId = list[0].companyId;
				/* var comLength = $("#comId option").length;
				console.log($("#comId option[index='"+i+"']").val); */
				
				$.ajax({
					type: 'get',
					url: report_service+'/getTicktOfficeByCom',
					/* beforeSend: function (request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, */
					data:{
						"comId":comId
					},
					cache:false,    
					dataType:'json',
					async: false,
					success: function(data){
						//var list = data.list;
						var list =  eval('(' + data.list + ')');
						for(var i=0;i<list.length;i++){
							var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
							$("#toId").append(option);
						}
					},
					error:function(){
						alert("请求失败");
					}
				});
				$("#toId").val(list[0].officeId);
				toId = list[0].officeId;
				$("#comId").attr("disabled","disabled");
				$("#toId").attr("disabled","disabled");
			}
			if(list[0].officeId.indexOf("1")==-1 && list[0].companyId.indexOf("1")==0){
				console.log("分公司人员登录");
				$("#comId").val(list[0].companyId);
				comId = list[0].companyId;
				$.ajax({
					type: 'get',
					url: report_service+'/getTicktOfficeByCom',
					/* beforeSend: function (request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, */
					data:{
						"comId":comId
					},
					cache:false,    
					dataType:'json',
					async: false,
					success: function(data){
						//var list = data.list;
						var list =  eval('(' + data.list + ')');
						for(var i=0;i<list.length;i++){
							var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
							$("#toId").append(option);
						}
					},
					error:function(){
						alert("请求失败");
					}
				});
				$("#comId").attr("disabled","disabled");
			}
		},
		error: function(data){
			console.log(data.msg);
		}
	});
	
	getPocketTag();
	
});

$("#comId").change(function(){
	$("#toId").empty();
	var comId = $(this).val();
	var targetUrl = report_service+'/getTicktOfficeByCom';
	if(comId == ''){
		//$("#toId").fadeOut("slow");
		return;
	}
	$.ajax({
		type: 'get',
		url: targetUrl,
		/* beforeSend: function (request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					}, */
		data:{
			"comId":comId
		},
		cache:false,    
		dataType:'json',  
		success: function(data){
			//var list = data.list;
			var list =  eval('(' + data.list + ')');
			var option2 = '<option value="">请选择票务室</option>';
			$("#toId").append(option2);
			for(var i=0;i<list.length;i++){
				var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
				$("#toId").append(option);
			}
		},
		error:function(){
			alert("请求失败");
		}
	});
});

function getPocketTag(){
	var mydate = new Date();
	var year = mydate.getFullYear();
	comId = $("#comId").val();
	toId = $("#toId").val();
	var quarter = $("#quarter").val();
	if(quarter!=0){
		quarter = year + quarter;
	}else{
		quarter = "";
	}
	var pocketTag = $("#pocketTag").val();
	
	$.ajax({
		data: {
			"comId": comId,
			"toId": toId,
			"quarter": quarter,
			"pocketTag": pocketTag
		},
		type: 'get',
		url: report_service+'/getPocketTag',
		dataType: 'json',
		async: false,
		success: function(data){
			myArray=new Array();
			var test = eval('(' + data.list + ')');
			var list;
			for (var i = 0; i < test.length; i++) {
				//list = eval('(' + test[i] + ')');
				list = test[i];
				myArray[i] = list;
			}
			console.log(myArray);
			$('.table-sort').dataTable({
				"aaSorting": [[ 1, "desc" ]],//默认第几个排序
				//"bStateSave": true,//状态保存
				"lengthMenu":[10, 50, 100],
				"pageLength": 100,
				"aoColumnDefs": [
				  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
				  //{"orderable":false,"aTargets":[0,5]}// 制定列不参与排序
				],
				destroy: true,
				data: myArray,
				columns: [
					//这里就是　　复选框　　*重点 也可以随便起名字比如叫check 
					{data: 'checkbox', className: 'text-c'},
					{data: 'companyid'},
					{data: 'officeid',"defaultContent":""},
					{data: 'code'},
					{data: 'type'},
					//{data: 'inuser'},
					{data: 'intime'},
					//{data: 'outuser',"defaultContent":""},
					{data: 'outtime',"defaultContent":""},
					{data: 'status'},
					{data: 'usetime',"defaultContent":""},
					{data: 'batchno'},
					{data: 'id',"visible": false}
				],
				columnDefs: [
					{
						targets: [0], // 目标列位置，下标从0开始
						bSortable: false,//是否排序
						render: function(data, type, row, meta) { // 返回自定义内容
							return '<input type="checkbox" value="'+row.code+','+row.id+'" name="codeCheckbox" class="checked">';
						}
					},
					{
						"targets": 1,
						"data": null,
						render: function(data, type, row, meta) {
							return "<td>"+$('#comId option[value="' + row.companyid + '"]').text()+"</td>";
						}
					},
					{
						"targets": 2,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.officeid == "null"){
								return "";
							}else{
								return "<td>"+$('#AllOffice option[value="' + row.officeid + '"]').text()+"</td>";
							}
						}
					},
					{
						"targets": 4,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.type == "0"){
								return "大包";
							}else{
								return "款包";
							}
						}
					},
					/**
					{
						"targets": 7,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.outuser == "null"){
								return "";
							}else{
								return "<td>"+row.outuser+"</td>";
							}
						}
					},
					**/
					{
						"targets": 6,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.outtime == "null"){
								return "";
							}else{
								return "<td>"+row.outtime+"</td>";
							}
						}
					},
					{
						"targets": 7,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.status == "0"){
								return "未使用";
							}else{
								return "已使用";
							}
						}
					},
					{
						"targets": 8,
						"data": null,
						render: function(data, type, row, meta) {
							if(row.usetime == "null"){
								return "";
							}else{
								return "<td>"+row.usetime+"</td>";
							}
						}
					}
				
				]
			});
		},
		error:function(data) {
			console.log(data.msg);
		},
	});
	
}

</script>
</body>
</html>